package ace.module.upms.core.impl.api.impl;

import ace.cmp.core.model.R;
import ace.module.common.api.annotation.ApiLocalPriority;
import ace.module.common.api.model.input.AppIdListInput;
import ace.module.common.core.impl.api.impl.SdkApiImpl;
import ace.module.upms.api.model.input.UpmsOrgBindAccountInput;
import ace.module.upms.core.impl.service.UpmsOrganizationService;
import java.util.List;
import java.util.Map;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;

import ace.module.upms.core.impl.api.impl.UpmsOrganizationApiImpl;
import ace.module.upms.core.impl.dao.entity.UpmsOrganization;
import ace.module.upms.api.model.dto.UpmsOrganizationDto;
import ace.module.upms.core.impl.manager.UpmsOrganizationManager;
import ace.module.upms.api.UpmsOrganizationApi;


/**
 * 组织 api implements.
 *
 * @author Caspar
 *
 */
@ApiLocalPriority
@AllArgsConstructor
@Component
public class UpmsOrganizationApiImpl
    extends SdkApiImpl<UpmsOrganization, Long, UpmsOrganizationDto, UpmsOrganizationManager>
    implements UpmsOrganizationApi {
  private final UpmsOrganizationService upmsOrganizationService;

  @Override
  public R<Map<Long, List<UpmsOrganizationDto>>> getAccountIdAndOrgMapByUpmsAppIdAndIamAccountIdIn(Long upmsAppId, List<Long> iamAccountIds) {
    Map<Long, List<UpmsOrganizationDto>> result = this.upmsOrganizationService.getAccountIdAndOrgMapByUpmsAppIdAndIamAccountIdIn(upmsAppId, iamAccountIds);
    return R.ok(result);
  }

  @Override
  public R<List<UpmsOrganizationDto>> getByUpmsApIdAndIamAccountId(Long upmsAppId, Long iamAccountId) {
    List<UpmsOrganizationDto> result = this.upmsOrganizationService.getByUpmsApIdAndIamAccountId(upmsAppId, iamAccountId);
    return R.ok(result);
  }

  @Override
  public R<Void> saveOrgAccountRelation(AppIdListInput<UpmsOrgBindAccountInput> inputs) {
    this.upmsOrganizationService.saveOrgAccountRelation(inputs);
    return R.ok();
  }
}
